package org.oc.qaq.controller;

import org.oc.qaq.dto.RoleDTO;
import org.oc.qaq.result.Result;
import org.oc.qaq.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/admin/roles")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping
    public Result<?> getRoles() {
        return roleService.listRoles();
    }

    @PostMapping
    public Result<?> addRole(@RequestBody RoleDTO roleDTO) {
        return roleService.add(roleDTO);
    }

    @PutMapping
    public Result<?> update(@RequestBody RoleDTO roleDTO) {
        return roleService.update(roleDTO);
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        return roleService.delete(id);
    }

    @DeleteMapping("/batch")
    public Result<?> deleteBatch(@RequestBody List<Long> ids) {
        return roleService.deleteBatch(ids);
    }

}
